{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "def veg_sum(X,Y):\n",
    "    date = ['7/28','7/29','7/30']\n",
    "    vegsum = []\n",
    "    for i in range(3):\n",
    "        sum = 0\n",
    "        for j in range(3):\n",
    "            sum += (X[i,j] * Y[j])\n",
    "        vegsum.append(sum)\n",
    "    print(vegsum)\n",
    "    for i in range(3):\n",
    "        print('日期：',date[i],'金额',vegsum[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "X = np.array([[1.2,1.5,1.8],[1.3,1.4,1.9],[1.1,1.6,1.7]])\n",
    "Y = np.array([5,10,9]).T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[37.2, 37.599999999999994, 36.8]\n",
      "日期： 7/28 金额 37.2\n",
      "日期： 7/29 金额 37.599999999999994\n",
      "日期： 7/30 金额 36.8\n",
      "Wall time: 998 µs\n"
     ]
    }
   ],
   "source": [
    "%time res = veg_sum(X,Y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "def veg_sum_dot(X,Y):\n",
    "    vegsum=np.dot(X,Y)\n",
    "    date=['7/28','7/29','7/30']\n",
    "    for i in range(3):\n",
    "        print('日期：',date[i],'金额',vegsum[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "X = np.array([[1.2,1.5,1.8],[1.3,1.4,1.9],[1.1,1.6,1.7]])\n",
    "Y = np.array([5,10,9]).T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "日期： 7/28 金额 37.2\n",
      "日期： 7/29 金额 37.599999999999994\n",
      "日期： 7/30 金额 36.8\n",
      "Wall time: 997 µs\n"
     ]
    }
   ],
   "source": [
    "%time res=veg_sum_dot(X,Y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
